<?php
/*
 * @Author: your name2
 * @Date: 2021-09-21 16:46:35
 * @LastEditTime: 2022-01-25 15:27:00
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /nlog/app/Http/Controllers/AdminController/Login.php
 */

namespace App\Http\Controllers\crm;


use Illuminate\Support\Facades\Request;
use App\Models\crm_model\CrmContract as CrmContractDb;                        // admins表

class CrmContract extends BaseController
{

    public function contractAdd()
    {
        return    redis_mysql_add('crm_contract');
    }

    public function contractEdit()
    {
        return    redis_mysql_edit('crm_contract');
    }


    public function contractSelOne()
    {
        return    redis_mysql_selone('crm_contract');
    }

    public function contractList()
    {
        // if(Request::has('division_id')){
            $whereStr = '';
            $limitStr = '';
            $division_id =  Request::has('division_id')? Request::input('division_id'):$this->getAdminInfo()['division_id'];
            if (Request::input('pageSize') && Request::input('page')) {
                $limitStr =   limit_joint(Request::input('page'), Request::input('pageSize'));
            }
            if(Request::has('keyWord')){
                $keyWord = array_filter(Request::input('keyWord'), 'filtrfunction');
                if(isset($keyWord['manyField'])){
                    $whereStr .= havaWhereLikeManyField($keyWord['manyField']);
                    unset($keyWord['manyField']);
                }
                if (!empty($keyWord)) {
                    $whereStr .= havaWhereLikeJoinEqual($keyWord);
                }
            }
          
            

            $list  =  CrmContractDb::contractList( $division_id ,$whereStr, $limitStr);
            $count =  CrmContractDb::contractCount($division_id ,$whereStr);
            return $this->create(200,'查询成功',['list'=>$list,'total'=>$count[0]['count']]);
       

    }
}
